<template>
  <!-- Dashboard -->
  <div class="page-container">
    <el-form :inline="true" label-width="100px" label-suffix=":">
      <el-row>
        <el-col :span="6">
          <el-form-item label="道路名称">
            <el-input
              v-model="formData.roadName"
              style="width: 100%"
              placeholder="请输入道路名称查询"
              clearable
            />
          </el-form-item>
        </el-col>
        <!-- 查询按钮 -->
        <el-col :span="4">
          <el-button type="primary" icon="el-icon-search" @click="fetchData">查询</el-button>
          <el-button plain icon="el-icon-refresh" @click="resetForm">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <div stylle="height: calc(100vh - 160px)" v-loading="listLoading"> 
      <el-table
        :data="list"
        border
        fit
        highlight-current-row
        style="height: 500px"
      >
        <el-table-column align="center" label="道路名称" prop="roadName"></el-table-column>
        <el-table-column align="center" label="道路类型" prop="a">
          <template slot-scope="scope">
            {{ scope.row.roadType | filterRoadType }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="车道数" prop="laneCount"></el-table-column>
        <el-table-column align="center" label="路宽" prop="roadWidth"></el-table-column>
        <el-table-column align="center" label="起点经度" prop="startLongitude"></el-table-column>
        <el-table-column align="center" label="起点纬度" prop="startLatitude"></el-table-column>
        <el-table-column align="center" label="终点经度" prop="endLongitude"></el-table-column>
        <el-table-column align="center" label="终点纬度" prop="endLatitude"></el-table-column>
        <el-table-column align="center" label="管理人姓名" prop="managerName"></el-table-column>
        <el-table-column align="center" label="规划员姓名" prop="plannerName"></el-table-column>
        <el-table-column align="center" label="操作" width="150px">
          <template slot-scope="scope">
            <span class="el-icon-e" @click="$refs.dialogIntersection.open(scope.row.id)">查看路口</span>
            <span class="el-icon-e" style="margin-left: 10px" @click="$refs.dialogLk.open(scope.row.id)">实时路况</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-top: 20px; text-align: center">
      <!-- 页码改变和页数改变事件 -->
      <el-pagination
        v-show="list"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
        :current-page="pageInfo.currentPage"
        :page-sizes="[10, 20, 30, 40, 50]"
        style="float: right"
        @current-change="currentPageChange"
        @size-change="sizeChange"
      />
    </div>

    <dialog-intersection ref="dialogIntersection"></dialog-intersection>
    <dialog-lk ref="dialogLk"></dialog-lk>

  </div>
</template>

<script>
import { mapGetters } from "vuex";
import dialogIntersection from "./components/dialogIntersection.vue";
import dialogLk from "./components/lkPopup.vue";
import { getTmRoadPage } from "@/api/tm-road";

export default {
  name: "Dashboard",
  computed: {
    ...mapGetters(["name"]),
  },
  components: {
    dialogIntersection,
    dialogLk
  },
  filters: {
    // 道路类型# 0'主干路', 1'次干路',2 '支路',3 '区间路'
    filterRoadType(value) {
      const roadType = ['主干路', '次干路', '支路', '区间路']
      return roadType[value]
    }
  },
  data() {
    return {
      formData: {
        roadName: '',
      },
      dateRange: [],
      listLoading: false,
      list: [
        { a: '123' }
      ], // 列表数据
      pageInfo: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
      },
    };
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    // 获取列表数据
    async fetchData() {
      this.listLoading = true;
      const params = {
        roadName: this.formData.roadName,
        pageNum: this.pageInfo.currentPage,
        pageSize: this.pageInfo.pageSize,
      }
      const { code = undefined, items = {} } = await getTmRoadPage({ ...params })
      if(code ===200){
        this.list = items.records;
        this.pageInfo.total = items.total
        setTimeout(() => {
          this.listLoading = false
        }, 200)
      }else{
        this.$message.error('获取数据失败')
        this.listLoading = false
      }
    },
    // 重置表单
    resetForm() {
      this.formData = {
        roadName: '',
      };
      this.fetchData() 
    },
    // 页码改变事件
    currentPageChange(currentPage) {
      this.pageInfo.currentPage = currentPage;
      this.fetchData()
    },
    // 页数改变事件
    sizeChange(pageSize) {
      this.pageInfo.pageSize = pageSize;
      this.fetchData()
    }
  },
};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
p {
    margin: 0;
    padding: 0;
}
#clock {
    font-family: 'Share Tech Mono', monospace;
    color: #ffffff;
    text-align: center;
    color: #3F9EFF;
    text-shadow: 0 0 3px yellow;
    .time {
        letter-spacing: 0.05em;
        font-size: 20px;
        padding: 5px 0;
    }
    .date {
        letter-spacing: 0.1em;
        font-size: 18px;
    }
    .text {
        letter-spacing: 0.1em;
        font-size: 12px;
        padding: 20px 0 0;
    }
}
</style>
